import 'package:hive/hive.dart';

part 'share_post_model.g.dart';

@HiveType(typeId: 5)
class SharePostModel extends HiveObject {
  @HiveField(0)
  String id;

  @HiveField(1)
  String userId;

  @HiveField(2)
  String description;

  @HiveField(3)
  List<String> imageUrls;

  @HiveField(4)
  List<String> viewerIds;

  @HiveField(5)
  DateTime createdAt;

  @HiveField(6)
  bool isCollected;

  SharePostModel({
    required this.id,
    required this.userId,
    required this.description,
    required this.imageUrls,
    List<String>? viewerIds,
    required this.createdAt,
    this.isCollected = false,
  }) : this.viewerIds = viewerIds ?? [];

  // 添加查看者
  void addViewer(String userId) {
    if (!viewerIds.contains(userId)) {
      viewerIds.add(userId);
    }
  }
}
